<?php
/**
 * Bet class
 *
 * @category   Bet
 * @package    Lib
 * @copyright  Copyright (c) 2010-2020  Mr.Khuyen(http://herofit.net)
 */
class betResult {
	var $url;
	var $datas;
	var $continue;
	var $log;
	/*
	 * contruction init get data
	* */
	function __construct(){
		//
	}
	/*
	 * return 
	 * array('bet_result'=> "WIN" or "LOSE",'bet_result_point'=>10);
	 * */
	function result($bet_type, $bet_rate, $bet_pos, $bet_point,$home_score,$away_core, $value_dynamic=0){
		//
	$result = array(
		'bet_result'=>'LOSE',
		'bet_result_point'=>0		
	);
		switch ($bet_type){
			case 'ft':
				//3Way - Result
				if($home_score > $away_core){
					// doi nha thang
					if($bet_pos == 'bet_val1'){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
					
				}else if($home_score < $away_core){
					// doi khach thang
					if($bet_pos == 'bet_val3'){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
				}else{
					//hoa
					// doi khach thang
					if($bet_pos == 'bet_val2'){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
				}
				break;
			case 'dc':
				//Double change
				if($bet_pos == 'bet_val1'){
					// chu nha thang hoac hoa
					if($home_score > $away_core || $home_score == $away_core){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
				}else if($bet_pos == 'bet_val2'){
					// doi khach thang hoac hoa
					if($home_score < $away_core || $home_score == $away_core){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
				}else{
					// tran dau ko hoa
					if($home_score < $away_core || $home_score > $away_core){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
				}				
				break;
			case 'ou':
				//over under
				$total = $home_score + $away_core;
				$ou_total = $value_dynamic;
				$raw = floor($ou_total);
				$decimal = $ou_total - $raw;
				
				if($bet_pos == 'bet_val1'){
					// over
					$sub = $total - $ou_total;
					if($sub >= 0){
						// win
						$result = array(
							'bet_result'=>'WIN',
							'bet_result_point'=>$this->ou_result($bet_point*$bet_rate, $sub)
						);
					}else{
						//lose
						$result = array(
							'bet_result'=>'LOSE',
							'bet_result_point'=>floor($bet_point)- $this->ou_result($bet_point, $sub)
						);
					}
				}else if($bet_pos == 'bet_val3'){
				// over
					$sub = $total - $ou_total;
					if($sub >= 0){
						// lost
						$result = array(
							'bet_result'=>'LOSE',
							'bet_result_point'=>floor($bet_point) - $this->ou_result($bet_point, $sub)
						);
					}else{
						//win
						$result = array(
							'bet_result'=>'WIN',
							'bet_result_point'=>$this->ou_result($bet_point*$bet_rate, $sub)
						);
					}
				}
				break;
			case "ts":
				//odds
				$parity= ($home_score + $away_core)%2;
				if($parity == 0){
					// chẵn even
					if($bet_pos == 'bet_val1'){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
					
				}else{
					//hoa
					// doi khach thang
					if($bet_pos == 'bet_val3'){
						$result = array(
								'bet_result'=>'WIN',
								'bet_result_point'=>floor($bet_point*$bet_rate)
						);
					}else{
						$result = array(
								'bet_result'=>'LOSE',
								'bet_result_point'=>0
						);
					}
				}
				break;
			case "ah":
				$plus = $home_score - $away_core;
				$score = $plus + $value_dynamic;
				if($bet_pos == 'bet_val1'){
					// neu dat doi chu nha(home)
					if($score >= 0){
						// win
						$result = array(
							'bet_result'=>'WIN',
							'bet_result_point'=>$this->handocap_result($bet_point*$bet_rate, $score)
						);
					}else{
						//lose
						$result = array(
							'bet_result'=>'LOSE',
							'bet_result_point'=>floor($bet_point) - $this->handocap_result($bet_point, $score)
						);
					}
				}else if($bet_pos == 'bet_val3'){
				// over
					$score = 0 - $score;
					if($score >= 0){
						// win
						$result = array(
							'bet_result'=>'WIN',
							'bet_result_point'=>$this->handocap_result($bet_point*$bet_rate, $score)
						);
					}else{
						//lose
						$result = array(
							'bet_result'=>'LOSE',
							'bet_result_point'=>floor($bet_point) - $this->handocap_result($bet_point, $score)
						);
					}
				}
				break;
			case "ahs":
				$plus = $home_score - $away_core;
				$score = $plus + $value_dynamic;
				if($bet_pos == 'bet_val1'){
					// neu dat doi chu nha(home)
					if($score >= 0){
						// win
						$result = array(
							'bet_result'=>'WIN',
							'bet_result_point'=>floor($bet_point*$bet_rate)+ $this->handocap_result($bet_point*$bet_rate, $score)
						);
					}else{
						//lose
						$result = array(
							'bet_result'=>'LOSE',
							'bet_result_point'=>floor($bet_point)- $this->handocap_result($bet_point, $score)
						);
					}
				}else if($bet_pos == 'bet_val3'){
				// over
					$score = 0 - $score;
					if($score >= 0){
						// win
						$result = array(
							'bet_result'=>'WIN',
							'bet_result_point'=>floor($bet_point*$bet_rate)+ $this->handocap_result($bet_point*$bet_rate, $score)
						);
					}else{
						//lose
						$result = array(
							'bet_result'=>'LOSE',
							'bet_result_point'=>floor($bet_point)- $this->handocap_result($bet_point, $score)
						);
					}
				}
				break;
				break;
		}
		
		return $result;
	}
	function ou_result($point, $sub){		
		if(abs($sub) == 0){
			return 0;
		}elseif(abs($sub) < 0.5){
			return floor($point/2);
		}else{
			return floor($point);
		}
	}
	function handocap_result($point, $val){
		if(abs($val) == 0){
			return $point;
		}elseif(abs($val) < 0.5){
			return floor($point/2);
		}else{
			return floor($point);
		}
	}
}

?>